Title: SQL W3S (By-BKK) / 106 Alter Table
Tags: Obsidian_to_Anki

Q: What does the ALTER TABLE statement do?
A: It is used to add, delete, or modify columns in an existing table

Q: True or False: ALTER TABLE can be used to add and drop constraints on a table
A: True

Q: How do you add a new column to a table using SQL?
A: Use ALTER TABLE table_name ADD column_name datatype

Q: Show the SQL statement to add an "Email" column of type varchar(255) to the "Customers" table
A: ALTER TABLE Customers ADD Email varchar(255);

Q: How do you delete a column from a table in SQL?
A: Use ALTER TABLE table_name DROP COLUMN column_name

Q: Show the SQL statement to delete the "Email" column from the "Customers" table
A: ALTER TABLE Customers DROP COLUMN Email

Q: How do you rename a column in a table in SQL (general syntax)?
A: Use ALTER TABLE table_name RENAME COLUMN old_name TO new_name

Q: How do you rename a column in SQL Server?
A: Use EXEC sp_rename 'table_name.old_name', 'new_name', 'COLUMN';

Q: How do you change a column’s data type in SQL Server or MS Access?
A: Use ALTER TABLE table_name ALTER COLUMN column_name datatype

Q: How do you change a column’s data type in MySQL or Oracle (prior version 10G)?
A: Use ALTER TABLE table_name MODIFY COLUMN column_name datatype

Q: How do you change a column’s data type in Oracle 10G and later?
A: Use ALTER TABLE table_name MODIFY column_name datatype

Q: True or False: The data type of a column controls the kind of data the column can hold
A: True

Q: Show the SQL statement to change the "DateOfBirth" column to type "year" in the "Persons" table
A: ALTER TABLE Persons ALTER COLUMN DateOfBirth year

Q: True or False: All database systems support deleting columns with ALTER TABLE
A: False

Q: Reverse card example:
ALTER TABLE Persons ADD DateOfBirth date;
A: Which SQL statement adds a "DateOfBirth" column of type date to the "Persons" table?

Q: Reverse card example:
ALTER TABLE Persons DROP COLUMN DateOfBirth;
A: Which SQL statement deletes the "DateOfBirth" column from the "Persons" table?